//
//  PYNavigationController.m
//  xuexi
//
//  Created by Jim on 2018/4/7.
//  Copyright © 2018年 Jim. All rights reserved.
//

#import "PYNavigationController.h"

@interface PYNavigationController () <UIGestureRecognizerDelegate, UINavigationControllerDelegate>

@end

@implementation PYNavigationController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationBar.barStyle = UIBarStyleDefault;
    
    self.navigationBar.backgroundColor = APP_NAVIGATION_COLOR;
    
    self.navigationBar.barTintColor = APP_NAVIGATION_COLOR;
    
    self.navigationBar.tintColor = PY_Dark_Color;
    
    self.navigationBar.translucent = NO;
    
    self.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:PY_Dark_Color, NSFontAttributeName:PingFang_SC_Bold(18)};
    
    self.interactivePopGestureRecognizer.delegate = self;
    
    [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    
    [self.navigationBar setShadowImage:[UIImage new]];
    
//    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
    self.delegate = self;
    
}

//拦截自定义手势的触发，并记录触发手势的开始位置
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    
    //导航控制器的根控制器不需要返回侧滑手势（如果不屏蔽会有奇怪的效果）
    if (self.childViewControllers.count == 1) {
        
        return NO;
    }
    
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    if ([otherGestureRecognizer.view isKindOfClass:[UITableView class]]) {
        
        return YES;
    }
    
    return NO;
}

#pragma mark - dealloc
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
